<?php
// Check to ensure this file is included in Joomla!
defined ( '_JEXEC' ) or die ();

class AdminUIHelper {

	public static $vmAdminAreaStarted = false;
	public static $backEnd = true;

    static function startAdminArea($backEnd=true) {
		if (JRequest::getWord ( 'format') =='pdf') return;
		if (JRequest::getWord ( 'tmpl') =='component') self::$backEnd=false;
    	if(self::$vmAdminAreaStarted) return;
    	self::$vmAdminAreaStarted = true;
		$front = JURI::root(true).'/components/com_svquanlycanbo/assets/';
		$admin = JURI::root(true).'/components/com_svquanlycanbo/assets/';
		$document = JFactory::getDocument();
		$document->addStyleSheet($front.'css/admin_ui.css');
		$document->addStyleSheet($front.'css/admin_menu.css');
		$document->addStyleSheet($front.'css/admin.styles.css');
		$document->addStyleSheet($front.'css/toolbar_images.css');
		$document->addStyleSheet($front.'css/menu_images.css');
		
		$document->addScript($front.'js/jquery.coookie.js');
		
		$document->addScript($front.'js/vm2admin.js');
		
		$document->addStyleSheet($front.'css/chosen.css');
		$document->addStyleSheet($front.'css/vtip.css');
		$document->addStyleSheet($front.'js/fancybox/jquery.fancybox-1.3.4.css');
		//$document->addStyleSheet($admin.'css/jqtransform.css');

		//loading defaut script

		$document->addScript($front.'js/fancybox/jquery.mousewheel-3.0.4.pack.js');
		$document->addScript($front.'js/fancybox/jquery.easing-1.3.pack.js');
		$document->addScript($front.'js/fancybox/jquery.fancybox-1.3.4.pack.js');
		
		$document->addScript($front.'js/chosen.jquery.min.js');
		
		//$document->addScript($admin.'js/jquery.jqtransform.js');
		if (JText::_('COM_VIRTUEMART_JS_STRINGS') == 'COM_VIRTUEMART_JS_STRINGS') $vm2string = "editImage: 'edit image',select_all_text: 'select all options',select_some_options_text: 'select some options'" ;
		else $vm2string = JText::_('COM_VIRTUEMART_JS_STRINGS') ;
		$document->addScriptDeclaration ( "
		var tip_image='".JURI::root(true)."/components/com_svquanlycanbo/assets/js/images/vtip_arrow.png';
		var vm2string ={".$vm2string."} ;
		 jQuery( function($) {

			$('dl#system-message').hide().slideDown(400);
			$('.virtuemart-admin-area .toggler').vm2admin('toggle');
			$('#admin-ui-menu').vm2admin('accordeon');
			if ( $('#admin-ui-tabs').length  ) {
				$('#admin-ui-tabs').vm2admin('tabs',virtuemartcookie).find('select').chosen({enable_select_all: true,select_all_text : vm2string.select_all_text,select_some_options_text:vm2string.select_some_options_text}); 
			}

			$('#content-box [title]').vm2admin('tips',tip_image);
			$('.modal').fancybox();
			$('.reset-value').click( function(e){
				e.preventDefault();
				none = '';
				jQuery(this).parent().find('.ui-autocomplete-input').val(none);
				
			});

		});
		");
		?>
		<?php if (!self::$backEnd) echo '<div class="toolbar" style="height: 84px;position: relative;">'.vmView::getToolbar().'</div>'; ?>
		<div class="virtuemart-admin-area">
		<?php
		// Include ALU System
		if (self::$backEnd) {
		?>

			<div class="menu-wrapper">
				<?php
                                 AdminUIHelper::showAdminMenu();
				?>
			</div>
		<?php } ?>
			<div id="admin-content-wrapper">
			<div class="toggler vmicon-show">
			</div>
				<div id="admin-content" class="admin-content">
		<?php
	}

	static function endAdminArea() {
		if (!self::$backEnd) return;
		self::$vmAdminAreaStarted = false;
		if (VmConfig::get('debug') == '1') {
		}
		?>
					<div class="clear"></div>
				</div>
			</div>
			<div class="clear"></div>
		</div>
	<?php
	    }

	static public function buildTabs($view, $load_template = array(),$cookieName='') {
		$cookieName = JRequest::getWord('view','svquanlycanbo').$cookieName;
		$document = JFactory::getDocument ();
		$document->addScriptDeclaration ( '
		var virtuemartcookie="'.$cookieName.'";
		');

		$html = '<div id="admin-ui-tabs">';

		foreach ( $load_template as $tab_content => $tab_title ) {
			$html .= '<div class="tabs" title="' . JText::_ ( $tab_title ) . '">';
			$html .= $view->loadTemplate ( $tab_content );
			$html .= '<div class="clear"></div></div>';
		}
		$html .= '</div>';
		echo $html;
	}

	static function _getAdminMenu($moduleId = 0) {
		$db = JFactory::getDBO ();
		$menuArr = array ();

		$filter [] = "jmmod.published='1'";
		$filter [] = "item.published='1'";
		$filter [] = "jmmod.is_admin='1'";
		if (! empty ( $moduleId )) {
			$filter [] = 'vmmod.module_id=' . ( int ) $moduleId;
		}

		$query = 'SELECT `jmmod`.`module_id`, `module_name`, `module_perms`, `id`, `name`, `link`, `depends`, `icon_class`, `controller`, `task`
						FROM `#__virtuemart_modules` AS jmmod
						LEFT JOIN `#__virtuemart_adminmenuentries` AS item ON `jmmod`.`module_id`=`item`.`module_id`
						WHERE  ' . implode ( ' AND ', $filter ) . '
						ORDER BY `jmmod`.`ordering`, `item`.`ordering` ';

		$db->setQuery ( $query );
		$result = $db->loadAssocList ();
		//		echo '<pre>'.print_r($query,1).'</pre>';
		for($i = 0, $n = 10; $i < $n; $i ++) {
			$row = $result [$i];
			$menuArr [$i] ['title'] =  $i;
			$menuArr [$i] ['items'] [] = $i ;
		}
		return $menuArr;
	}

	/**
	 * Display the administrative ribbon menu.
	 * @todo The link should be done better
	 */
	static function showAdminMenu() {
		?>
		<div id="admin-ui-menu" class="admin-ui-menu">
			<h3 class="menu-title">
			Home
			</h3>
			<div class="menu-list">
				<ul>
					<li>
						<a href="index.php?option=com_svquanlycanbo&view=home" ><span class="">Trang chủ</span></a>
						<a href="index.php?option=com_svquanlycanbo&view=home" ><span class="">Giới thiệu</span></a>
						<a href="index.php?option=com_svquanlycanbo&view=home" ><span class="">Search</span></a>
					</li>
			    </ul>
			</div>
			<!-- ---------------------------------------- -->
			<h3 class="menu-title">
			Hồ sơ cán bộ
			</h3>
			<div class="menu-list">
				<ul>
					<li>
						<a href="index.php?option=com_svquanlycanbo&view=canbo" ><span class="">Sơ yếu lí lịch</span></a>
					</li>
			    </ul>
			</div>
			<!-- ---------------------------------------- -->
			<h3 class="menu-title">
			Cơ cấu tổ chức
			</h3>
			<div class="menu-list">
				<ul>
					<li>
				    	<a href="index.php?option=com_svquanlycanbo&view=phongban&lanhdao=1" ><span class="">Bộ máy lãnh đạo</span></a>
						<a href="index.php?option=com_svquanlycanbo&view=donviquanly" ><span class="">Danh sách đơn vị</span></a>
						<a href="index.php?option=com_svquanlycanbo&view=phongban" ><span class="">Danh sách phòng ban</span></a>
					</li>
			    </ul>
			</div>
			<!-- ---------------------------------------- -->
		</div>
	<?php
	}

}

?>